local anjian = fk.CreateSkill{
  name = "hanqing__anjian",
}

Fk:loadTranslationTable{
  ["hanqing__anjian"] = "暗间",
  [":hanqing__anjian"] = "你可以将一张牌当【洞烛先机】使用。若〖暗间〗发动次数大于〖枭獍〗，则不摸牌。若使用牌不为黑色手牌，则不卜算。",

  ["#hanqing__anjian"] = "暗间：你可以将一张牌当【洞烛先机】使用",
  ["#hanqing__anjian0"] = "暗间：你可以将一张牌当【洞烛先机】使用（本次【洞烛先机】不摸牌！）",

  ["$hanqing__anjian1"] = "用间当如事亲，非小惠不成大谋。",
  ["$hanqing__anjian2"] = "宫中声息，朝夕相通，有变必先告我。",
}

anjian:addEffect("viewas", {
  anim_type = "drawcard",
  pattern = "foresight",
  prompt = function (self, player)
    if player:usedSkillTimes(anjian.name, Player.HistoryGame) < player:usedSkillTimes("hanqing__xiaojing", Player.HistoryGame) then
      return "#hanqing__anjian"
    else
      return "#hanqing__anjian0"
    end
  end,
  handly_pile = true,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0
  end,
  view_as = function(self, player, cards)
    if #cards ~= 1 then return end
    local card = Fk:cloneCard("foresight")
    card.skillName = anjian.name
    card:addSubcard(cards[1])
    return card
  end,
  before_use = function (self, player, use)
    local id = use.card.subcards[1]
    if Fk:getCardById(id).color ~= Card.Black or not table.contains(player:getCardIds("h"), id) then
      use.extra_data = {}
      use.extra_data.hanqing__anjian = true
    end
    local card = use.card:clone()
    local c = table.simpleClone(use.card)
    for k, v in pairs(c) do
      card[k] = v
    end
    card.skill = Fk.skills["hanqing__anjian__foresight_skill"]
    use.card = card
  end,
  enabled_at_response = function (self, player, response)
    return not response
  end,
})

anjian:addAI(nil, "vs_skill")

return anjian
